require(quanteda)

dict <- dictionary(file = 'keywords.yml')
dat <- readRDS("class.RDS")

toks <- readRDS("data/tokens_nytimes_summary.RDS")
docvars(toks) <- dat

toks <- tokens_subset(toks, country.class != "us")
dfmt_ideo <- toks %>% 
    tokens_lookup(dict$count$ideology) %>% 
    dfm() %>% 
    dfm_group("year")
mt_ideo <- as.matrix((t(dfm_weight(t(dfmt_ideo), "propmax"))))

dfmt_tech <- toks %>% 
    tokens_lookup(dict$count$technology) %>% 
    dfm() %>% 
    dfm_group("year")
mt_tech <- as.matrix((t(dfm_weight(t(dfmt_tech), "propmax"))))   

save(mt_ideo, mt_tech , file = "matrix_dictionary.RDA")


